package common_phrase

import (
	common_phrase_db "hft/Database/admin/common_phrase"
	"hft/Http/Models/request"
	"hft/Http/Services/common_phrase"
	utils "hft/Http/Utils"

	"github.com/gin-gonic/gin"
)

type CommonPhraseCate struct{}

func (*CommonPhraseCate) List(c *gin.Context) {
	list := common_phrase.CommonPhraseCateService.List()
	utils.OkWithData(list, c)
}

func (*CommonPhraseCate) Add(c *gin.Context) {
	var data *common_phrase_db.CommonPhraseCate
	c.ShouldBindJSON(&data)
	if err := common_phrase.CommonPhraseCateService.Add(data); err != nil {
		utils.FailWithMessage(err.Error(), c)
	} else {
		utils.Ok(c)
	}
}

func (*CommonPhraseCate) Edit(c *gin.Context) {
	var data *common_phrase_db.CommonPhraseCate
	c.ShouldBindJSON(&data)
	if err := common_phrase.CommonPhraseCateService.Edit(data); err != nil {
		utils.FailWithMessage(err.Error(), c)
	} else {
		utils.Ok(c)
	}
}

func (*CommonPhraseCate) Delete(c *gin.Context) {
	var ids request.IDS
	c.ShouldBindJSON(&ids)
	if err := common_phrase.CommonPhraseCateService.Delete(ids.IDS); err != nil {
		utils.FailWithMessage(err.Error(), c)
	} else {
		utils.Ok(c)
	}
}

var CommonPhraseCateController = new(CommonPhraseCate)
